/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gerenciadorfinanceiro.controller.resources;

import gerenciadorfinanceiro.database.resources.User;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.orm.jpa.support.JpaDaoSupport;

/**
 *
 * @author eduardo
 */
public class UserDAO extends JpaDaoSupport {

    public List getAllUsers() {
        return this.getJpaTemplate().find("select u from User u");
    }

    public User getUserByName(String name) {
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("nameUser", name);

        List l = this.getJpaTemplate().findByNamedQueryAndNamedParams("User.findByNameUser", m);

        if (l.size() == 1) {
            return (User)l.get(0);
        } if (l.size() > 1) {
            return null;
        }else {
            return null;
        }
    }

}
